(function($) {
 //        FB.init({ 
 //           appId:'498062800337', cookie:true, 
 //           status:true, xfbml:true 
 //        });	
	// Agent Data
	var FirstName;
	var LastName;
	var OfficePhone;
	var CellPhone;
	var Email;
	// Broker Data
	var BrokerName;
	var BrokerOfficePhone;
	var BrokerCellPhone;
	var BrokerEmail;
	// Proporty Data
	var PropertyID = 0;
	var Favorites = new Array();
	
	// Google API
	var geocoder;		// obj to change address
	var targetLocation;	// Property Target Position lat / lon
	var myLocation;		// My Position				lat / lon	

	var PMap;
	var myPositionMarker;
	var tgPositionMarker = new google.maps.Marker();
	
	var Map;
	var SearchMarker = new Array();
	var nMarkerPageIdx = 0, nPageNum = 25;
	var infowindow = new google.maps.InfoWindow();
	var strInfoContent = new Array();
	
	var NearMap;
	var cityCircle;
	var ChPage;
          
	var MinPriceSale = new Array( "No Min Price", "$100,000", "$200,000", "$300,000", "$400,000", "$500,000", "$750,000", "$1,000,000", "$2,000,000", "$3,000,000", "$4,000,000" );
	var MaxPriceSale = new Array( "No Max Price", "$200,000", "$300,000", "$400,000", "$500,000", "$750,000", "$1,000,000", "$2,000,000", "$3,000,000", "$4,000,000", "$5,000,000" );
	var MinPriceRent = new Array( "No Min Price", "$150", "$200", "$300", "$400", "$500", "$750", "$1,000", "$2,000", "$3,000" );
	var MaxPriceRent = new Array( "No Max Price", "$200", "$300", "$400", "$500", "$750", "$1,000", "$2,000", "$3,000", "$4,000" );

	function initialize() {

		
		var mapOptions = {
			zoom: 8,
			center: new google.maps.LatLng(0, 0),
			disableDefaultUI: true,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		PMap = new google.maps.Map( document.getElementById('PropertyMap'), mapOptions);
		Map = new google.maps.Map( document.getElementById('Map'), mapOptions);
		NearMap = new google.maps.Map( document.getElementById('Radar'), mapOptions);
			
		var populationOptions = {
            strokeColor: '#FFFF00',
            strokeOpacity: 0.35,
            strokeWeight: 0,
            fillColor: '#FFFF00',
            fillOpacity: 0.35,
            map: NearMap,
            center: new google.maps.LatLng(0, 0),
            radius: 10
          };
		  cityCircle = new google.maps.Circle(populationOptions);
//		google.maps.event.addListener(Map, 'click', function() { infoWindow.close(); });

	}
	google.maps.event.addDomListener(window, 'load', initialize);	
	
	$(document).ready(function(e){//bind('pageinit', function(e){//

//		SearchAgent(e);
//		AdvanceSearch(e);
		$('#BtNotAgent').click(RandomAgent);
		$('.ListSearchAgent').click(SearchAgentBtn);	// Button or Search Bar for Search List
		$('#searchinput1').keyup(SearchAgent);			// Button or Search Bar for Search List
		//$('#YesChangeAgent').click(ChangeAgent)
//		$('#searchinput1').keydown(SearchAgent);		// Button or Search Bar for Search List
//		$('#searchinput1').change(SearchAgent);			// Button or Search Bar for Search List
							
//		$('.AgentDetailBtn').click(AgentDetail);
//		$('.for-sale').click( UIClickSale );
//		$('.for-rent').click( UIClickRent );
		$('#BtFavoritesSearch').click(FavoritesSearch);
		$('#BtOpenHouseSearch').click(OpenHouseSearch);
//		$('#BtAgentDetailBack').click(AgentDetailBack);
		////////////////////////////////////////////////////////////	
		// Build Advance Search Option
		$('#BtAdvancedSearch').click(BuildAdvanceSearch);
		$('#AdSearchSlae').click(BuildAdvanceSearch);
		$('#AdSearchRent').click(BuildAdvanceSearch);
		$('#selectmenu4').change(BuildAdvanceSearchCity);		// Borough
//		$('#selectmenu5').change(BuildAdvanceSearchBorough);	// Neighbourhoof

//		$('#BtAdvancedSearch').click(BuildAdvanceSearchDyn);	
//		$('#AdSearchSlae').click(BuildAdvanceSearchDyn);
//		$('#AdSearchRent').click(BuildAdvanceSearchDyn);
//		$('#selectmenu4').change(BuildAdvanceSearchDyn);		// Borough
//		$('#selectmenu5').change(BuildAdvanceSearchDyn);	// Neighbourhoof
		$('#selectmenu1').change(BuildMaxPrice);		// Price
		$('#selectmenu6').change(BuildMinPrice);	// Bedrooms
//		$('#selectmenu3').change(BuildAdvanceSearchDyn);		// Bathrooms
//		$('#selectmenu7').change(BuildAdvanceSearchDyn);	// Neighbourhoof
//		$('#selectmenu8').change(BuildAdvanceSearchDyn);		// Borough
		
		$('.ListLocationSearch').click(LocationSearch);
		$('.ListAdvanceSearch').click(AdvanceSearch);

		$('#P10PreBtn').click(PreNextBtn); 
		$('#P10NextBtn').click(PreNextBtn); 

		// Page 11 Event
		////////////////////////////////////////////////////////////	
		// Page 14 Event
		$('#BtAddMyNote').click(AddMyNote);
		$('#BtTakeMeThere').click(TakeMeThere);
		//$('#BtShareItemFB').click(ShareItemFB);
		
//		$('#BtFBProperty').click(ShareItemFB);
//		$('#BtTWProperty').click(TWProperty);
		
		
//		$('#BtCallAgent').click(CallAgent);
		////////////////////////////////////////////////////////////
		
//		$('#Clear').click(clearStorage);
//		$('.ToPage14').click(ViewDetail);
		
		////////////////////////////////////////////////////////////	
		// Page 16
		$('#BtSaveNote').click(SaveNote);
		$('#BtDeleteNote').click(DeleteNote);
		var $window = $( window );
		$( '#textarea1' ).height( $window.height() * 0.8 );
  		$( '#textarea1' ).width( $window.width() * 0.9);
		
		geocoder = new google.maps.Geocoder();
/*		
		for( var i = 0 ; i < 25 ; i++)
		{
			var Temp = new google.maps.Marker({
									position: new google.maps.LatLng(0,0),
									map: null});
			SearchMarker.push( Temp );
		}
*/		
		//ListImgUI();
		//////////////////////////////////////////////////////////
		// Big Map
		$('.BtMapResults').click(ViewMapResults); 
		$('#BtMSate').click(MSate);
		$('#BtMNext').click(MNext);
		
		$('#BtPropertyMap').click(ViewPropertyMap);
		$('#BtPSate').click(PSate);
		$('#BtPShow').click(PShow);

		$('#BtBrokerMap').click(ViewBrokerMap);
		$('#BtNearMe').click(ViewNearMap);
	
		$('#sliderRadar').click(ViewChangeRadius);

		//////////////////////////////////////////////////////////
		// Favorites
		$('#BtAddMyFavorites').click(AddMyFavorites);
		$('#BtFavoritesEdit').click(EditFavorites);
		//////////////////////////////////////////////////////////
		// Contacts		
		$('.BtAddMyContact').click(AddMyContact);		
		//////////////////////////////////////////////////////////
		// Mail
		$('#BtMailToAgent').click(MailToAgent);
		$('#BtMailToBroker').click(MailToBroker);
		$('#BtMailFriend').click(MailFriend);
		$('#BtMailAgent').click(MailAgent);
		//////////////////////////////////////////////////////////
		// Share
		$('#BtMoreFB').click(ShareAppFB);
		$('#BtMoreTW').click(ShareAppTW);
		$('#BtMoreMS').click(ShareAppMS);
		$('#BtBrokerFB').click(ShareBrokerFB);
		$('#BtBrokerTW').click(ShareBrokerTW);
		$('#BtBrokerMS').click(ShareBrokerMS);
		$('#BtDetailFB').click(ShareDetailFB);
		$('#BtDetailTW').click(ShareDetailTW);
		$('#BtDetailMS').click(ShareDetailMS);
		//////////////////////////////////////////////////////////
		// Power By		
		$('#BtPowerBy').click(PowerBy);
	});
$('#sliderRadar').live('change', ViewChangeRadius);
$('#searchinput1').live('change',SearchAgent);			// Button or Search Bar for Search List

	var strWebSite = "http://23.21.84.9/";
	
//	function clearStorage(e)
//	{
//		window.localStorage.removeItem("Favorites")
//	}
	/**function ChangeAgent(e)
	{
		window.location.hash = "#page4";
		SearchAgentBtn();
		$('#Page4Back').attr( "href", "#page7");
		confirm( 'Are you sure to change your agent',
											onChangeAgent,
											'Change Agent',
											'Yes, No');
	}**/
	
	/**function onChangeAgent( button )
	{
			window.location = 'index.html#page4';
		if( button === 1 )
		{
			SearchAgentBtn();
		}
	}**/
	
	function RandomAgent(e)
	{
		$.post( strWebSite + 'SearchAgent.php',
			function(data){
				$("#BtRandomAgent").attr("id",$(data).find("ID").text());
				$('.AgentSelect').click(AgentListBtn);	
		});
	}
		
	function SearchAgentBtn(e)
	{
		switch( $(this).attr("id") )
		{
			case "Page1ToPage4":
				$('#Page4Back').attr( "href", "#page1");
				break;
			case "Page5ToPage4":
				$('#Page4Back').attr( "href", "#page5");
				break;
			case "Page7ToPage4":
				$('#Page4Back').attr( "href", "#page7");
				break;
		}
		SearchAgent(e,null);//, $(this).attr("id") 
		
		window.location ="#page4";
		
	}

	function SearchAgent(e,ui)//, CallerID
	{
		var cpage = $.mobile.activePage.attr('id');
		if((cpage=="page1")||(cpage=="page5"))
			ChPage = cpage;
		
		var strAgent = $("#searchinput1").val();
//	if( CallerID != null )
//		{
//			var ID = CallerID;
//		}
//		else
//		{
//			var ID = 0;
//		}
		$.post( strWebSite + 'SearchAgent1.php',
			{"SelectKey": strAgent, "CheckPage": ChPage},//,"Href": ID
			function(data){
			$("#SearchAgentList").html(data);
			$('.AgentSelect').click(AgentListBtn);		// Search Button To Page 6 (Main Page) or Page 7( More Page- Change Agent ) 		
		});
		
	}

	function AgentListBtn(e)
	{
		if (ChPage=="page5")
			$("#BtAgentDetailBack").attr("href", "#page4");
		var AgentID = $(this).attr("id");
		$.post( strWebSite + 'SelectAgent.php',
			{"AgentID": AgentID},
			function(data){
				$("#ViewAgentDetail").html(data);
			});
		$.post( strWebSite + 'SelectBroker.php',
			function(data){
				$("#ViewBrokerDetail").html(data);
			});
		$.post( strWebSite + 'AgentConnect.php',
		function(data)
		{
			FirstName = $(data).find("FirstName").text();
			LastName = $(data).find("LastName").text();
			OfficePhone = $(data).find("OfficePhone").text();
			CellPhone = $(data).find("CellPhone").text();
			Email = $(data).find("Email").text();

			$("#BtCallAgent").attr("href","tel:"+OfficePhone);
		});			
	}

	function BuildAdvanceSearch(e)
	{
		$.post(strWebSite + 'ListSelectCity.php',
			function(data)
			{
				$("#selectmenu4").html(data);
				$('select#selectmenu4').trigger("change");
//				$("#selectmenu4").text("Any");
			}
		);
		BuildAdvanceSearchCity(e);
		if($('#AdSearchSlae').hasClass("ui-btn-active"))
		{
			$('#selectmenu7').html('<option selected="selected" value="-1">Any</option><option value="1">Residential</option><option value="4">Commercial</option>');
//			<option selected="selected" value="2">LotsAndLand</option>
//			<option selected="selected" value="3">Multifamily</option>
			
		}
		else
		{
			$('#selectmenu7').html('<option selected="selected" value="-1">Any</option>');
		}
		$('select#selectmenu7').trigger("change");
	}
	function BuildAdvanceSearchCity(e)
	{
		$.post(strWebSite + 'ListSelectBorough.php',
			{"City": $("#selectmenu4 :selected").text()},
			function(data){
				$("#selectmenu5").html(data);
				$('select#selectmenu5').trigger("change");
//				$("#selectmenu5").text("Any");			
			}
		);
		BuildAdvanceSearchBorough(e);
	}
	function BuildAdvanceSearchBorough(e)
	{
/*		var isSale = $('#AdSearchSlae').hasClass("ui-btn-active");
		$.post(strWebSite + 'ListSelectPrice.php',
//			{"City": $("#selectmenu4 :selected").text(),
//			"Borough": $("#selectmenu5 :selected").text()},
			{"isSale": isSale},
			function(data){
//				$("#test").html(data);
				$("#selectmenu1").html(data);
				$('select#selectmenu1').trigger("change");
//				$("#selectmenu1").text("Any");
			}
		);		
*/

		if( $('#AdSearchSlae').hasClass("ui-btn-active") )
		{
			var MinData = "";
			for( var i in MinPriceSale )
			{
//				if(i == 0)
//				MinData +=  '<option selected="selected" value="'+ i +'">'+ MinPriceSale[i] +'</option>';
//				else
				MinData +=  '<option value="'+ i +'">'+ MinPriceSale[i] +'</option>';
			}
			var MaxData = "";
			for( var i in MaxPriceSale )
			{
//				if(i == 0)
//				MaxData +=  '<option selected="selected" value="'+ i +'">'+ MaxPriceSale[i] +'</option>';
//				else
				MaxData +=  '<option value="'+ i +'">'+ MaxPriceSale[i] +'</option>';
			}
		}
		else
		{
			var MinData = "";
			for( var i in MinPriceRent )
			{
//				if(i == 0)
//					MinData +=  '<option selected="selected" value="'+ i +'">'+ MinPriceRent[i] +'</option>';
//				else
				MinData +=  '<option value="'+ i +'">'+ MinPriceRent[i] +'</option>';
			}
			var MaxData = "";
			for( var i in MaxPriceRent )
			{
//				if(i == 0)
//				MaxData +=  '<option selected="selected" value="'+ i +'">'+ MaxPriceRent[i] +'</option>';
//				else
				MaxData +=  '<option value="'+ i +'">'+ MaxPriceRent[i] +'</option>';
			}
		}
		
		$("#selectmenu1").html(MinData);
		$('select#selectmenu1 option:first').attr("selected","true");
		$('select#selectmenu1').trigger("change");
		$("#selectmenu6").html(MaxData);
		$('select#selectmenu6 option:first').attr("selected","true");
		$('select#selectmenu6').trigger("change");
		
		BuildAdvanceSearchPrice(e);		
	}
	
	function BuildMinPrice(e)
	{
		var MaxIdx = $("#selectmenu6 :selected").val();
		var MinIdx = $("#selectmenu1 :selected").val();
		
		// ReBuild selectmenu1
		var MinArray;
		if( $('#AdSearchSlae').hasClass("ui-btn-active") )
			MinArray = MinPriceSale;
		else
			MinArray = MinPriceRent;
		var MinData = "";	
		for( var i in MinArray )
		{
			if( i == MinIdx )
			{
				MinData +=  '<option selected="selected" value="'+ i +'">'+ MinArray[i] +'</option>';				
			}
			else
			{
				MinData +=  '<option value="'+ i +'">'+ MinArray[i] +'</option>';
			}
			if( MaxIdx != 0 && i == MaxIdx)
			{
				break;
			}
		}
	
		$("#selectmenu1").html(MinData);
		// Max Idx == 0 nothing
		if( MaxIdx == 0 || MinIdx == 0)
		{
		}
		else if( MinIdx > MaxIdx)
		{
			$('select#selectmenu1 option:first').attr("selected","true");
			$('select#selectmenu1').trigger("change");
		}
	}
	
	function BuildMaxPrice(e)
	{
		var MaxIdx = $("#selectmenu6 :selected").val();
		var MinIdx = $("#selectmenu1 :selected").val();
		
		// ReBuild selectmenu1
		var MaxArray;
		if( $('#AdSearchSlae').hasClass("ui-btn-active") )
			MaxArray = MaxPriceSale;
		else
			MaxArray = MaxPriceRent;
		var MaxData = "";	
		for( var i in MaxArray )
		{
			if( i != 0 && i < MinIdx)
			{
				continue;
			}
			if( i == MaxIdx )
			{
			  MaxData +=  '<option selected="selected" value="'+ i +'">'+ MaxArray[i] +'</option>';
			}
			else
			{
				MaxData +=  '<option value="'+ i +'">'+ MaxArray[i] +'</option>';
			}
		}
	
		$("#selectmenu6").html(MaxData);
		// Max Idx == 0 nothing
		if( MaxIdx == 0 || MinIdx == 0)
		{
		}
		else if( MinIdx > MaxIdx)
		{
			$('select#selectmenu6 option:first').attr("selected","true");
			$('select#selectmenu6').trigger("change");
		}	
	}
	
	function BuildAdvanceSearchPrice(e)
	{
		var isSale = $('#AdSearchSlae').hasClass("ui-btn-active");
		$.post(strWebSite + 'ListSelectSqFt.php',
			{"isSale": isSale},
//			{"City": $("#selectmenu4 :selected").text(),
//			"Borough": $("#selectmenu5 :selected").text()},
			function(data){
//				$("#test").html(data);
				$("#selectmenu8").html(data);
				$('select#selectmenu8').trigger("change");
//				$("#selectmenu1").text("Any");
			}
		);
	}	
	function BuildAdvanceSearchDyn(e)
	{
		var isSale = $('#AdSearchSlae').hasClass("ui-btn-active");
		var Borough = $("#selectmenu4 :selected").text();
		var Neighbourhood = $("#selectmenu5 :selected").text();
		var Price = $("#selectmenu1 :selected").val();
		var Bedrooms = $("#selectmenu2 :selected").val();
		var Bathrooms = $("#selectmenu3 :selected").val();
		var Types = $("#selectmenu7 :selected").val();
		var SqFt = $("#selectmenu7 :selected").val();
		
		$.post(strWebSite + 'DynButAdvSearch.php',
		{	"isSale": isForSale,	"Borough": Borough,		"Neighbor": Neighbor,
			"Price": Price, 		"Bedrooms": Bedrooms,	"Bathrooms": Bathrooms,
			"Types": Types, 		"SqFt": SqFt,
		},
		function(data){
//			var BoroughList			= $(data).find("Borough").text();
			var BoroughList			= $(data).find("Borough").text();
			var NeighbourhoodList	= $(data).find("Neighbourhood").text();
			var PriceList			= $(data).find("Price").text();
			var BedroomsList		= $(data).find("Bedrooms").text();
			var BathroomsList		= $(data).find("Bathrooms").text();
			var TypesList			= $(data).find("Types").text();
			var SqFtList			= $(data).find("SqFt").text();	
		});
	}
				
	function LocationSearch(e)
	{
		var strLocation = $("#searchinput3").val();
		var isForSale = $('#SearchSlae').hasClass("ui-btn-active");
			//Search / Favorites GUI Setting 
			Page10GUISetting(0);
		$.post( strWebSite + 'SearchProperties.php',
		{"strLocation": strLocation,
		"isSale": isForSale},
		function(data){
			$("#ListResult").html(data);
			PropertyListFormat();
			$('#BtBackFromList').attr("href", "#page6");
			$('.ViewDetailBlock').click(ViewDetail);
			ListImgUI();
		});
	}
	
	function AdvanceSearch(e){
		var City = $("#selectmenu4 :selected").text();
		var Neighbor = $("#selectmenu5 :selected").text();
		//var Neighbor = $("#selectmenu6 :selected").text();
		if( $("#selectmenu1 :selected").val() == 0 )
		{
			var MinPrice = 0;
		}
		else
		{
			var MinPrice = $("#selectmenu1 :selected").text().replace(/,/g,"").replace("$","");
		}
		if( $("#selectmenu6 :selected").val() == 0 )
		{
			var MaxPrice = 0;
		}
		else
		{
			var MaxPrice = $("#selectmenu6 :selected").text().replace(/,/g,"").replace("$","");;
		}
		var Bedrooms = $("#selectmenu2 :selected").val();
		var Bathrooms = $("#selectmenu3 :selected").val();
		var Type = $("#selectmenu7 :selected").val();
		var SqLt = $("#selectmenu8 :selected").val();
		var isForSale = $('#AdSearchSlae').hasClass("ui-btn-active")
			//Search / Favorites GUI Setting 
			Page10GUISetting(0);
		$.post(strWebSite + 'AdvSearch.php',
		{"City": City,
//		"Borough": Borough,
		"Neighbor": Neighbor,
		"MinPrice": MinPrice,
		"MaxPrice": MaxPrice,
		"Bedrooms": Bedrooms,
		"Bathrooms": Bathrooms,
		"Type": Type,
		"SqLt": SqLt,
		"isSale": isForSale},
		function(data){
			$("#ListResult").html(data);
			$('#BtBackFromList').attr("href", "#page9");
			$('.ViewDetailBlock').click(ViewDetail);
			ListImgUI();			
		});
	}
	//------------------------------------------------Search / Favorites GUI Setting 			
	function Page10GUISetting( nFavorites )
	{
		$('.ViewDetailBlock').unbind("click");
		$("#BtFavoritesEdit > span > span").text("Edit");
		//$("#BtFavoritesEdit").css("font-size","12.5px");		
		if( nFavorites == 1)
		{
			$(".BtListResults > font").html( "List Favorites" );
			$(".BtMapResults > font").text( "Map Favorites" );			
			$("#ListTitle").html( "Favorites" );
			$("#BtFavoritesEdit").show();
		}
		else
		{
			$(".BtListResults > font").html( "List Result" );
			$(".BtMapResults > font").text( "Map Result" );			
			$("#ListTitle").html( "Search Results" );			
			$("#BtFavoritesEdit").hide();			
		}
	}
	function ListImgUI()
	{
		if( $('.ListImage').height() == 0)
			$('.property-image').height( "105px" );
		else
			$('.property-image').height( $('.ListImage').height() );
//		$('.property-image').height( "105px" );
//		$('.property-image').css("height", $('.ListImage').css("height"));
//		var strWidth = ($('.property-image-text').width() - $('.ListPrice').width()).toString() +"px";
//		var strHeight = ($('.property-image-text').height() - $('.ListPrice').height()).toString() +"px";
//		$('.ListPrice').css("margin-left", strWidth);
//		$('.ListPrice').css("margin-top",  strHeight);
	}
	
	function OpenHouseSearch(e)
	{
		$('#BtOpenHouseSearch').removeClass("ui-btn-active");
		$('#BtOpenHouseSearch').addClass("ui-btn-up-c");
		alert("Sorry, there are no open houses at this time");
		//$('#BtOpenHouseSearch').attr('enable',false)
		//$(this).unbind(event);
		//$("#BtOpenHouseSearch").unbind("click");
	}

	//------------------------------------------------End of Search / Favorites GUI Setting			
	function FavoritesSearch(e)
	{
//		var strLocation = $("#searchinput3").val();
//		var isForSale = $('#SearchSlae').hasClass("ui-btn-active")
			//Search / Favorites GUI Setting 
			Page10GUISetting(1);
		$.post( strWebSite + 'FavoritesProperties.php',
//		{"Favorites": $("#ListResult").html( window.localStorage.getItem("Favorites") )},
		{"Favorites": window.localStorage.getItem("Favorites") },
		function(data){
			$("#ListResult").html(data);			
			$('#BtBackFromList').attr("href", "#page6");
			$('.ViewDetailBlock').click(ViewDetail);
			ListImgUI();
		});
	}
		
	function PreNextBtn(e)
	{
//		var strLocation = $("#searchinput3").val();
			//Search / Favorites GUI Setting 
			$('.ViewDetailBlock').unbind("click");
		$.post( strWebSite + 'SearchProperties2.php',
		{//"strLocation": strLocation,
		"Caller": $(this).attr("id")},
		function(data){
			$("#ListResult").html(data);
//			$('#BtBackFromList').attr("href", "#page6");
			if( $('#BtFavoritesEdit > span > span').text() == "Edit" )
			{	
				$('.ViewDetailBlock').click(ViewDetail); 
			}
			else
			{
				$('.ViewDetailBlock').click(RemoveFavorites); 
				$('.ViewDetailBlock').attr("href","#"); 
			}
//			$('#P10PreBtn').click(LocationSearch2); 
//			$('#P10NextBtn').click(LocationSearch2);
			ListImgUI();
		});
	}	

	function PropertyListFormat()
	{
		var height = $('.property-image-src').height();
		$('.property-image-text').css("margin-top",height*0.9);
		var width = $('.property-image-src').width();
		$('.property-image-text').css("margin-left",width*0.9);
	}
	//---------------View Detail
	function ViewDetail(e){
		PropertyID = $(this).attr("id");
				
		GetPropertyDetail(PropertyID);
	}
	
	function GetPropertyDetail( PropertyID )
	{
		$.post( strWebSite + 'PropertyDetails.php',
			{"arg": PropertyID,"Show": 0},
			function(data)
			{
				$("#PropertiesDetail").html(data);	
				//------------------------------------------- Image Box	
				$('.iosSlider').iosSlider(
				{
					scrollbar: true,
					snapToChildren: true,
					desktopClickDrag: true,
					scrollbarLocation: 'top',
					scrollbarMargin: '10px 10px 0 10px',
					scrollbarBorderRadius: '0',
					responsiveSlideWidth: true,
					infiniteSlider: false,
					startAtSlide: '1'
				});
				
				//------------------------------------------- address turn to LatLng	
				var strURL = $('#ProperMap').attr("style");
				var Start = strURL.search("center=") + 7;
				var End = strURL.search("&zoom=");
				var address = strURL.substr(Start,End-Start ).split("%20");				
	//			alert( address );
	//			address = address.replace("%20"," ");
				geocoder.geocode( { 'address': address.join(" ")}, function(results, status)
				{
					if (status == google.maps.GeocoderStatus.OK)
					{
						targetLocation = results[0].geometry.location;
						//alert(targetLocation);
						var newImage = 'url(https://maps.googleapis.com/maps/api/staticmap'
									 + '?zoom=14&size=288x200&markers=color:blue%7Clabel:P%7C'
									 + targetLocation.lat() + ',' + targetLocation.lng() 
									 + '&sensor=false)';
						//document.getElementById('ProperMap').style.backgroundImage = newImage;
						$('#ProperMap').css("background-Image", newImage);					
					}
					else
					{
	//					alert( address );
						alert("Geocode was not successful for the following reason: " + status);
					}
				});				
				//------------------------------------------- End of address turn to LatLng		
				var height = $('.slider').css("height");
				$('.iosSlider').css("height", height );	
				$('#MyPosition').click(MyPos);
			});		
	}
		
	function MyPos(e)
	{
		if( $('#MyPosition').text() == "Show Me" )
		{
//			alert( $('#MapCanvas').html() );
			navigator.geolocation.getCurrentPosition(ShowMeSuccess, GPSLocationError);
			$('#MyPosition').html( "Hide Me" );
		}
		else
		{
			$('#MyPosition').html( "Show Me" );

		var newImage = 'url(https://maps.googleapis.com/maps/api/staticmap?zoom=14&size=288x200&markers=color:blue%7Clabel:P%7C'+targetLocation.lat()+','+targetLocation.lng()+'&sensor=false)';
        //document.getElementById('ProperMap').style.backgroundImage = newImage;
		$('#ProperMap').css("background-Image", newImage);
//			$('#ProperMap').attr("style", 'background-image: url(https://maps.googleapis.com/maps/api/staticmap?size=288x200&markers=color:blue%7Clabel:P%7C'+targetLocation+'&sensor=false); width: 288px; height: 200px; position: absolute;');
			//alert( $('#MapCanvas').html() );
			//alert( newImage );
		}
		
	}
	// onSuccess Callback
	var ShowMeSuccess = function(position)
	{
		// center location = position + targetLocation / 2
		myLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
		var Contain = new google.maps.LatLngBounds();
		Contain.extend(myLocation);
		Contain.extend(targetLocation);
		//alert(myLocation);
		//alert(targetLocation);
		var center = Contain.getCenter();

		var newImage =  'url(https://maps.googleapis.com/maps/api/staticmap?size=288x200&markers=color:blue%7Clabel:P%7C'+targetLocation.lat()+','+targetLocation.lng()+'&markers=label:M%7C'+myLocation.lat()+','+myLocation.lng()+'&sensor=false)';
        //document.getElementById('ProperMap').style.backgroundImage = newImage;
		$('#ProperMap').css("background-image", newImage);
		
//		$('#ProperMap').attr("style", 'background-image: url(https://maps.googleapis.com/maps/api/staticmap?size=288x200&markers=color:blue%7Clabel:P%7C'+targetLocation+'&markers=label:C%7C'+myLocation+'&sensor=false); width: 288px; height: 200px; position: absolute;');

		//alert( $('#MapCanvas').html() );
	};

////////////////-----------------------Google Map--------------------------/////////////////
	function ViewPropertyMap(e){
//		$.post(strWebSite + 'PropertyMap.php',
//			//{"arg": idProperty},
//			function(data){
//				$("#PropertyMap").html(data);
//		});
//		alert( $('#PropertyMap').height() + " " + $('#PropertyMap').width() );
		tgPositionMarker.setMap(null);				

		tgPositionMarker = new google.maps.Marker({
			position: targetLocation,
			map: PMap});
//		PMap.setCenter( tgPositionMarker.getPosition() );
		PMap.setZoom( 14 );	
		PMap.setCenter( new google.maps.LatLng( 
				(tgPositionMarker.getPosition().lat() + 0.013) ,
				(tgPositionMarker.getPosition().lng() - 0.013) ));
		
	}
	function PSate(e)
	{
		if(PMap.getMapTypeId() == "roadmap")
		{
			PMap.setMapTypeId( google.maps.MapTypeId.HYBRID );
		}
		else
		{
			PMap.setMapTypeId( google.maps.MapTypeId.ROADMAP );
		}
	}
	function PShow(e)
	{
		if( $('#BtPShow').text() == "Show Me")
		{
			$('#BtPShow > span').text( "Hide Me" );
			getMyPosition();
		}
		else
		{
			$('#BtPShow > span').text( "Show Me" );
			PMap.setCenter( tgPositionMarker.getPosition() );
			PMap.setZoom( 14 );
			myPositionMarker.setMap(null);				
		}
	}
	function getMyPosition()
	{
		navigator.geolocation.getCurrentPosition(GetMyLocation, GPSLocationError);
	}
	var GetMyLocation = function(position) {
		myLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
			myPositionMarker = new google.maps.Marker({
				position: myLocation,
            	map: PMap});

			PMap.setCenter( new google.maps.LatLng( 
				(tgPositionMarker.getPosition().lat() + myPositionMarker.getPosition().lat()) / 2,
				(tgPositionMarker.getPosition().lng() + myPositionMarker.getPosition().lng()) / 2) );
			
			// Fit Bounds SW?:NE?	
			if( tgPositionMarker.getPosition().lat() > myPositionMarker.getPosition().lat() )
			{
				var nLatMin = myPositionMarker.getPosition().lat();
				var nLatMax = tgPositionMarker.getPosition().lat();				
			}
			else
			{
				var nLatMax = myPositionMarker.getPosition().lat();
				var nLatMin = tgPositionMarker.getPosition().lat();				
			}
			if( tgPositionMarker.getPosition().lng() > myPositionMarker.getPosition().lng() )
			{
				var nLngMin = myPositionMarker.getPosition().lng();
				var nLngMax = tgPositionMarker.getPosition().lng();				
			}
			else
			{
				var nLngMax = myPositionMarker.getPosition().lng();
				var nLngMin = tgPositionMarker.getPosition().lng();				
			}
						
			PMap.fitBounds( new google.maps.LatLngBounds( new google.maps.LatLng(nLatMin, nLngMin), new google.maps.LatLng(nLatMax, nLngMax) ) );
	};	
		
	function ViewMapResults(e)
	{
//**************---------------Clear Marker-----------------********************//
		//for( var i = nIdx+1 ; i < nPageNum ; i++)
		for (var i in SearchMarker)
		{
			SearchMarker[i].setMap(null);
		}
		SearchMarker = [];
		strInfoContent = [];
//		infowindow = [];
		nMarkerPageIdx = 0;
		if( $('.ListAddress').length > 0)
			TurnAddressToLatLng( 0 );
	}
	
	function TurnAddressToLatLng( nIdx )
	{
		//------------------------------------------- address turn to LatLng
		if( $('.property-image')[nIdx].id == 0 &&  $('.property-description')[nIdx].id == 0)
		{
			geocoder.geocode( { 'address': $('.ListAddress')[nIdx].textContent }, function(results, status)
			{
				if (status == google.maps.GeocoderStatus.OK)
				{
					MarkLatLng( nIdx, results[0].geometry.location.lat(), results[0].geometry.location.lng() );
				}
				else
				{
					if( status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT)
					{
						var nSleep = 400;
						Map.setCenter( SearchMarker[0].getPosition() );
						Map.setZoom( 10 );
						sleep(nSleep);
						TurnAddressToLatLng( nIdx );
					}
					else
					{
						alert("Geocode was not successful for the following reason: " + status + " nIdx: " + nIdx);
					}					
				}
			});
		}
		else
		{
			MarkLatLng( nIdx, $('.property-image')[nIdx].id, $('.property-description')[nIdx].id );
		}
	}

	function MarkLatLng( nIdx, lat, lng )
	{
		var SearchLocation = new google.maps.LatLng(lat, lng);				
//	Add Marker	
		SearchMarker.push( new google.maps.Marker({
							position: SearchLocation,
							map: Map}) );
//  Marker Content HTML Data
		var ID = $('.ViewDetailBlock')[nIdx].id;
		var Img = $('.property-image-canvas > img')[nIdx].outerHTML.replace('hspace="0" class="ListImage">', 'style="width:88px;">');
		var Price = $('.ListPrice')[nIdx].innerText;
		var Address1 = $('.property-description')[nIdx].firstChild.firstChild.textContent;
		var Address2 = $('.property-description')[nIdx].firstChild.lastChild.textContent;
		var Room = $('.property-description')[nIdx].lastChild.firstChild.textContent.replace(',', ',<br/>');
		var Score = $('.property-description')[nIdx].lastChild.lastChild.textContent;

		var strContent ='<a href="#page14" style="text-decoration: none; color: #000000;">';
		strContent +=		'<div class="ui-grid-a" style="width=170px">';
		strContent +=			'<div class="ui-block-a" style="width: 88px">';
		strContent += 				Img;
		strContent += 			'</div>';
		strContent +=			'<div class="ui-block-b" style="font-size: 11px">';
		strContent += 				'<font>'+	Address1+'</font><br/>';
		strContent += 				'<font>'+	Address2+'</font><br/>';
		strContent += 				'<font>'+	Room	+'</font><br/>';
		strContent += 				'<font>'+	Price	+'</font><br/>';
		strContent += 				'<font>'+	Score	+'</font><br/>';
		strContent += 			'</div>';
		strContent += 		'</div>';
		strContent += '</a>';

		strInfoContent.push( strContent );
				
		var MarkerIdx = nMarkerPageIdx * nPageNum + nIdx;
		google.maps.event.addListener(SearchMarker[MarkerIdx], 'click', function() 
		{
			infowindow.setContent(strInfoContent[MarkerIdx]);
			infowindow.open(SearchMarker[MarkerIdx].get('map'), SearchMarker[MarkerIdx] );
			google.maps.event.addListener(infowindow, 'click', GetPropertyDetail(ID) );
		});
					
//**************---------------Call Back Recursive-----------------********************//
		if( nIdx+1 < $('.ListAddress').length )
		{		
			TurnAddressToLatLng( nIdx+1 );
		}
//**************---------------End of Call Back Recursive-----------------********************//
		else
		{		

//	fitBounds & Counter Center	
			var nLatMin = SearchMarker[0].getPosition().lat();
			var nLngMin = SearchMarker[0].getPosition().lng();
			var nLatMax = SearchMarker[0].getPosition().lat();
			var nLngMax = SearchMarker[0].getPosition().lng();
					
			for( var j in SearchMarker)
			{
				if( nLatMin > SearchMarker[j].getPosition().lat())
					nLatMin = SearchMarker[j].getPosition().lat();
				else if( nLatMax < SearchMarker[j].getPosition().lat())
					nLatMax = SearchMarker[j].getPosition().lat();
				if( nLngMin > SearchMarker[j].getPosition().lng())
					nLngMin = SearchMarker[j].getPosition().lng();
				else if( nLngMax < SearchMarker[j].getPosition().lng())
					nLngMax = SearchMarker[j].getPosition().lng();
			}
					
			var SWPos = new google.maps.LatLng(nLatMin, nLngMin);
			var NEPos = new google.maps.LatLng(nLatMax, nLngMax);
			var Bound = new google.maps.LatLngBounds( SWPos,NEPos );
			
//			$.queue( 'add', 'fitBounds', function( Bound ){
//				alert( "test");
			$.post( strWebSite + 'nothing.php',
			function(data){
				Map.fitBounds( Bound );
			});

		}			
		//------------------------------------------- End of address turn to LatLng	
	}

	function MSate(e)
	{
		if(Map.getMapTypeId() == "roadmap")
		{
			Map.setMapTypeId( google.maps.MapTypeId.HYBRID );
		}
		else
		{
			Map.setMapTypeId( google.maps.MapTypeId.ROADMAP );
		}
	}
	function MNext(e)
	{
//**************---------------Clear Marker-----------------********************//
//		for( var i = nIdx+1 ; i < nPageNum ; i++)
//		{
//			SearchMarker[i].setMap(null);
//		}
		nMarkerPageIdx++;
		$('.ViewDetailBlock').unbind("click");
		$.post( strWebSite + 'SearchProperties2.php',
		{//"strLocation": strLocation,
		"Caller": "P10NextBtn"},
		function(data){
			$("#ListResult").html(data);
//			$('#BtBackFromList').attr("href", "#page6");
			if( $('#BtFavoritesEdit > span > span').text() == "Edit" )
			{	
				$('.ViewDetailBlock').click(ViewDetail); 
			}
			else
			{
				$('.ViewDetailBlock').click(RemoveFavorites); 
				$('.ViewDetailBlock').attr("href","#"); 
			}
			ListImgUI();
			if( $('.ListAddress').length > 0)
				TurnAddressToLatLng( 0 );		
		});
	}
	
	function ViewNearMap(e)
	{
		navigator.geolocation.getCurrentPosition(ShowNearMeSuccess, GPSLocationError);
		NearMap.setZoom( 10 );	
	}	
	// onSuccess Callback
	var ShowNearMeSuccess = function(position)
	{
		// center location = position + targetLocation / 2
		myLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
		var center = new google.maps.LatLng(position.coords.latitude+0.16, position.coords.longitude-0.22);
		NearMap.setCenter(center);
		
		cityCircle.setCenter(myLocation);
		cityCircle.setRadius( 10000 );
	};
	function ViewChangeRadius(e)
	{
		NearMap.setCenter(myLocation);
		
		cityCircle.setRadius( $('#sliderRadar').val() * 100);
	}
	
	function ViewBrokerMap(e)
	{
		$.post( strWebSite + 'BrokerMap.php',
		function(data){
			$("#BrokerMap").html(data);
		});		
	}
	
	
//	function ViewDetail(e)
//	{
//		var idProperty = $(this).attr("id");
//		$.post(strWebSite + 'AgentDetails.php',
//		function(data){
//			$("#ViewAgentDetail").html(data);
//		});
//		$.post(strWebSite+'PropertyMap.php',
//		//{"arg": idProperty},
//		function(data){
//			$("#Map").html(data);
//		});
//	}
	
/*
			//---------------Zip Code Search
			$("#Page6Search").click(function(){
				var strLocation = $("#searchinput3").val();
				$.post('SearchProperties2.php',
				{"arg": strLocation},
				function(data){
					$("#ListResult").html(data);
				});
			});
*/			
/*
			
			$("#Page10Detail").click(function(){
				var idProperty = $("#Property").val();
				$.post('PropertyDetails.php',
				{"arg": idProperty},
				function(data){
					$("#PropertiesDetail").html(data);
				});
				$.post('PropertyMap.php',
				//{"arg": idProperty},
				function(data){
					$("#Map").html(data);
				});
			});
			//---------------View Detail
			$(".PropertyDetail").click(function(){
				//var idProperty = $(".Property").val();
				$.post('PropertyDetails.php',
				//{"arg": idProperty},
				function(data){
					$("#PropertiesDetail").html(data);
				});
				//$.post('PropertyMap.php',
				//{"arg": idProperty},
				//function(data){
				//	$("#Map").html(data);
				//});
			});
*/		
		function AddMyNote(e)
		{
			$('#textarea1').val(window.localStorage.getItem(PropertyID));
			//fileSystem.getFile( PropertyID, {create: false, exclusive: false}, ReadFile, fail);
		}
		function TakeMeThere(e)
		{
			navigator.notification.confirm( 'This will take you away from our app and into Google Maps app. Are you sure you want to do this?',
												onTakeMeThere,
												'Take Me There',
												'Yes, No');
			
//			window.location = "maps:ll=38.870454,-77.055702";
		}
		function onTakeMeThere( button )
		{
			if( button === 1 )
			{
				navigator.geolocation.getCurrentPosition(MapSuccess, GPSLocationError);
			}
		}
		function AddMyContact(e)
		{
//			$.post( strWebSite + 'AgentConnect.php',
//			function(data)
//			{
//				 FirstName = $(data).find("FirstName").text();
//				 LastName = $(data).find("LastName").text();
//				 OfficePhone = $(data).find("OfficePhone").text();
//				 CellPhone = $(data).find("CellPhone").text();
//				 Email = $(data).find("Email").text();

				navigator.notification.confirm( 'Are you sure you want to add ' + FirstName + ' ' + LastName + ' to your Contacts',
												onAddContact,
												'Add Agent to your Contact',
												'Yes, No');
//				$("#PropertiesDetail").append(data);
//			});
		}
		function CallAgent(e)
		{
/*			$.post( strWebSite + 'AgentConnect.php',
			function(data)
			{
				Email = $(data).find("Email").text();
				window.location = 'tel:'.OfficePhone ;	
			});
*/		}
		// End of Page 14 Button Group
		// Page 14 Map
		// onSuccess Callback
		var MapSuccess = function(position) {
			$.post(strWebSite + 'PropertyDirection.php',
			function(data){
	    		var localLat = position.coords.latitude;
				var localLon = position.coords.longitude;
				window.location = "http://maps.google.com/maps?saddr=("+localLat+","+localLon+")&daddr="+data;
			});
		};

		// onError Callback receives a PositionError object
		//

		// End Page 14 Map
		// Page 14 AddContact Group
		function onAddContact( button )
		{
			if( button === 1 )
			{
				var NewContact = navigator.contacts.create();
				NewContact.displayName = FirstName;
				NewContact.nickname = FirstName;       //specify both to support all devices
				NewContact.name = new ContactName();
				NewContact.name.givenName = FirstName;
				NewContact.name.familyName = LastName;
				NewContact.emails = new Array();
				NewContact.emails.push( new ContactField('home', Email, true));
				NewContact.phoneNumbers = new Array();
				NewContact.phoneNumbers.push( new ContactField('home', OfficePhone, true));
				NewContact.phoneNumbers.push( new ContactField('mobile', CellPhone, false));
				NewContact.save( onSuccess, onFail);
			}
		}

		function onSuccess( contact ){ alert("Saved Successfully", null, "Save Contact"); }
		function onFail(contactError){ navigator.notification.alert( contactError.code, null, "Save Contact" ); }
		// End Page 14 AddContact Group
		// Page 16 Note
		function ReadFile(fileEntry)
		{
			fileEntry.file(gotFile, fail);
		}
		function gotFile(file)
		{
			var reader = new FileReader();
			reader.onloadend = function(evt) {
            	console.log("Read as text");
            	console.log(evt.target.result);
        	};
        	reader.readAsText(file);
		}
		function SaveNote(e)
		{
			window.localStorage.setItem(PropertyID,$('#textarea1').val());
		}
		function DeleteNote(e)
		{
			window.localStorage.removeItem(PropertyID);
		}
		// End of Page 16 Note


		//---------------------------Favorites Add/Remove---------------------------//
		function AddMyFavorites(e)
		{
			if( window.localStorage.getItem("Favorites") != null)
				Favorites = window.localStorage.getItem("Favorites").split(",");
			
			if(jQuery.inArray(PropertyID, Favorites) == -1)
			{
				if(Favorites == null)
					Favorites = Array(PropertyID);
				else
					Favorites.push( PropertyID );
				window.localStorage.setItem("Favorites",Favorites);
				alert( "Add this property to your Favorites" );				
			}
			else
			{
				alert( "This Item is already in your Favorites" );
			}
//			alert( window.localStorage.getItem("Favorites") );
		}
		
	function EditFavorites(e)
	{
		$('.ViewDetailBlock').unbind("click");
		if( $('#BtFavoritesEdit > span > span').text() == "Edit" )
		{
			$('#BtFavoritesEdit > span > span').text("Done");
			$('.ViewDetailBlock').click(RemoveFavorites); 
			$('.ViewDetailBlock').attr("href","#"); 
		}
		else
		{
			$('#BtFavoritesEdit > span > span').text("Edit");
			$('.ViewDetailBlock').click(ViewDetail); 
			$('.ViewDetailBlock').attr("href","#page14"); 			
		}
//		$("#BtFavoritesEdit").css("font-size","12.5px");		
		
	}
		
		function RemoveFavorites(e)
		{
			// get delete ID
			PropertyID = $(this).attr("id");
			// get Favorites List
			if( window.localStorage.getItem("Favorites") != null)
				Favorites = window.localStorage.getItem("Favorites").split(",");
			// Search delete ID in List
			if(jQuery.inArray(PropertyID, Favorites) != -1)
			{
				Favorites.splice( jQuery.inArray(PropertyID, Favorites), 1);	
			}
			// Save back to Favorites
			window.localStorage.setItem("Favorites",Favorites);
			// reflesh Favorites List
			$('.ViewDetailBlock').unbind("click");

			$.post( strWebSite + 'SearchProperties2.php',
			{//"strLocation": strLocation,
			"Caller": $(this).attr("class"),
			"Favorites": window.localStorage.getItem("Favorites")},
			function(data){
				$("#ListResult").html(data);
	//			$('#BtBackFromList').attr("href", "#page6");
				$('.ViewDetailBlock').click(RemoveFavorites); 
				$('.ViewDetailBlock').attr("href","#"); 
	//			$('#P10PreBtn').click(LocationSearch2); 
	//			$('#P10NextBtn').click(LocationSearch2);
				ListImgUI(); 
			});
			
		}		
		//---------------------------Enf of Favorites Add/Remove---------------------------//
	
		//---------------------------Share---------------------------//
//		$('#BtMoreFB').click(ShareAppFB);
		function ShareAppFB(e)
		{
			var str = "https://www.facebook.com/dialog/feed?"
  					+ "app_id=498062800337&"
					+ "link=http://23.21.84.9/Download/IPhone/RealtyApp.html&"
					+ "picture="+ encodeURIComponent("http://23.21.84.9/images/BOR.png") +"&"
					+ "name=RealtySmartApp&"
					+ "caption=Download%20RealtyApp%20Application&"
//					+ "description="+$('#BrokerAddress').text().split(" ").join("%20")+"&"
					+ "redirect_uri=http://ec2-23-21-84-9.compute-1.amazonaws.com/index.html";
			window.open(str);
		}
//		$('#BtMoreTW').click(ShareAppTW);
		function ShareAppTW(e)
		{
			window.open(  "http://twitter.com/share?"
						+ "url=http://23.21.84.9/Download/IPhone/RealtyApp.html&"
						+ "text=Download%20RealtySmartApp%20here&");
		}
//		$('#BtMoreMS').click(ShareAppMS);
		function ShareAppMS(e)
		{
//			window.open('sms:?body='.concat(encodeURIComponent("http://23.21.84.9/Download/")));
			window.location.href = 'sms:?body='.concat(encodeURIComponent("http://23.21.84.9/Download/"));
//			send("", "http://23.21.84.9/Download/");
		}
//		$('#BtBrokerFB').click(ShareBrokerFB);
		function ShareBrokerFB(e)
		{
			var str = "https://www.facebook.com/dialog/feed?"
  					+ "app_id=498062800337&"
					+ "link=http://23.21.84.9/index.html&"
					+ "picture="+ encodeURIComponent($('#BrokerImg').attr("src")) +"&"
					+ "name="+$('#BrokerName').text().split(" ").join("%20")+"&"
					+ "caption=My%20Broker%20Contact%20Details:&"
					+ "description="+$('#BrokerAddress').text().split(" ").join("%20")+"&"
					+ "redirect_uri=http://ec2-23-21-84-9.compute-1.amazonaws.com/index.html";

			window.open(str);
//			window.open('http://www.facebook.com/share.php?u=' .concat(encodeURIComponent("http://23.21.84.9/index.html#page14")));
		}
//		$('#BtBrokerTW').click(ShareBrokerTW);
		function ShareBrokerTW(e)
		{
			window.open(  "http://twitter.com/share?"
						+ "url=http://23.21.84.9/index.html&"
						+ "text="+$('#BrokerName').text().split(" ").join("%20")+"%0D%0A"
						+ $('#BrokerAddress').text().split(" ").join("%20") + "&");
		}
//		$('#BtBrokerMS').click(ShareBrokerMS);
		function ShareBrokerMS(e)
		{
			send("", "http://23.21.84.9/index.html");
		}
//		$('#BtDetailFB').click(ShareDetailFB);

		function ShareDetailFB(e)
		{
			var address = $('#PropertyStreet').text().split(" ").join("%20");
			var str = "https://www.facebook.com/dialog/feed?"
  					+ "app_id=498062800337&"
					+ "link=http://23.21.84.9/index.html&"
					+ "picture="+ encodeURIComponent($('#PropertyImg1').attr("src")) +"&"
					+ "name=Check%20out%20this%20property%20I%20found%20on%20the%20RealtySmartApps&"
					+ "caption="+address+"&"
					+ "description="+$('#PropertyPrice').text()+"&"
					+ "redirect_uri=http://ec2-23-21-84-9.compute-1.amazonaws.com/index.html";

			window.open(str);
		}
//		$('#BtDetailTW').click(ShareDetailTW);
		function ShareDetailTW(e)
		{
			window.open(  "http://twitter.com/share?"
						+ "url=http://23.21.84.9/index.html&"
						+ "text=Check%20out%20this%20property%20I%20found%20on%20the%20RealtySmartApps%0D%0A"
						+ $('#PropertyStreet').text().split(" ").join("%20")+"%0D%0A"
						+ $('#PropertyPrice').text().split(" ").join("%20") + "&");
		}				
//		$('#BtDetailMS').click(ShareDetailMS);			
		function ShareDetailMS(e)
		{
			send("", "http://23.21.84.9/index.html#14");
		}
		//---------------------------End of Share---------------------------//
		//---------------------------Mail---------------------------//
//		$('#BtMailToAgent').click(MailToAgent);
		function MailToAgent(e)
		{
			window.location='mailto:'+Email ;	
		}
//		$('#BtMailToBroker').click(MailToBroker);
		function MailToBroker(e)
		{
			window.location='mailto:'+Email ;	
		}
//		$('#BtMailFriend').click(MailFriend);
		function MailFriend(e)
		{
//			var strDetail = $('#propertyparams').html().replace("<p>"," ");
//			strDetail = strDetail.replace("</p>","%0D%0A");
//			for( str in array)
//			{
//				alert(str);
//			}
			window.location='mailto:?subject=Check out this property i found on the RealtySmartApps&body=Hi, Just thought you should know about this property i found today.%0D%0A' +$('#PropertiesDetail').html()/*+ strDetail+ encodeURIComponent($('#propertydescription').text())*/ ;	
		}
//		$('#BtMailAgent').click(MailAgent);
		function MailAgent(e)
		{
//			alert( $('.property-params').text() );mailto:email@address?subject='RealtyApp'&body='http://23.21.84.9/index.html'
//			alert( $('.property-description').text() );
//alert( location.host );
			window.location='mailto:'+Email+'?subject= I am interested in this property from RealtySmartApps&body=%0D%0A' + $('#PropertiesDetail').html();
		}

		//---------------------------End of Mail---------------------------//
		//---------------------------Power By---------------------------//
		function PowerBy(e)
		{
//			$.mobile.loadPage("http://www.realtysmartapps.com/");
//			$('#MyBrowser').loadPage("http://www.realtysmartapps.com/");
//			$('#MyBrowser').trigger("pagecreate").trigger("refresh");
//			$('#Browser')
//		var el=document.getElementById("MyBrowser");
//		el.innerHTML='<iframe src="http://www.realtysmartapps.com/"></iframe>'//$('#Browser').inne
		}
		//---------------------------End of Power By---------------------------//
		//---------------------------Map And GSP---------------------------//
		function GPSLocationError(error) {
    		alert('code: '    + error.code    + '\n' + 'message: ' + error.message + '\n');
		}
		//---------------------------End of Map And GSP---------------------------//
		
	function sleep(n) 
    { 
        var   start=new   Date().getTime(); 
        while(true)   if(new   Date().getTime()-start> n)   break; 
    } 

})(jQuery);
